import Dao.*;
import factory.MilkTeaOperationFactory;
import factory.OrderOperationFactory;
import factory.UserOperationFactory;
import interfac.MilkTeaOperation;
import interfac.OrderOperation;
import interfac.UserOperation;
import pojo.User;

import java.util.*;

public class MilkApp {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        boolean logged=false;
        while (!logged) {
            System.out.println("请输入用户名:");
            String username = scanner.next().trim();
            System.out.println("请输入密码:");
            String password = scanner.next().trim();
            User loggedInUser = Login.login(username, password);
            if (loggedInUser!=null) {
                System.out.println("登录成功");
                logged = true;
                app_show(scanner);
            } else {
                System.out.println("登录失败");
            }
        }
    }

    private static void app_show(Scanner scanner) {

        boolean running = true;

        while (running) {
            scanner.nextLine();
            System.out.println("----奶茶销售管理系统----");
            System.out.println("1. 奶茶点单");
            System.out.println("2. 进货");
            System.out.println("3. 完成订单");
            System.out.println("4. 查看订单");
            System.out.println("5. 奶茶管理");
            System.out.println("6. 员工管理");
            System.out.println("7. 生成今日销售报告");
            System.out.println("8. 退出");

            try {
                System.out.print("请选择操作 (1-8): ");
                int choice = Integer.parseInt(scanner.nextLine().trim());
                if (choice == 8) {
                    app_show(scanner);
                    running = false;
                    continue;
                }else if(choice == 6){
                    user_manage(scanner);
                    running = false;
                    continue;
                }else if (choice == 5){
                    milk_tea_manage(scanner);
                    running = false;
                    continue;
                }


                OrderOperation operation = OrderOperationFactory.getOperation(choice);
                if (operation != null) {
                    operation.execute(scanner);
                } else {
                    System.out.println("无效选择，请重新输入。");
                }
            } catch (NumberFormatException e) {
                System.out.println("请输入有效的数字选项。");
            }
        }
    }

    private static void user_manage(Scanner scanner) {
        boolean running = true;

        while (running) {
            System.out.println("----员工管理系统----");
            System.out.println("1. 查看全部员工");
            System.out.println("2. 添加新员工");
            System.out.println("3. 删除员工");
            System.out.println("4. 修改员工信息");
            System.out.println("5. 退出");

            try {
                System.out.print("请选择操作 (1-5): ");
                int choice = Integer.parseInt(scanner.nextLine());

                if (choice == 5) {
                    app_show(scanner);
                    running = false;
                    continue;
                }

                UserOperation operation = UserOperationFactory.getOperation(choice);
                if (operation != null) {
                    operation.execute(scanner);
                } else {
                    System.out.println("无效选择，请重新输入。");
                }
            } catch (NumberFormatException e) {
                System.out.println("请输入有效的数字选项。");
            }
        }
    }

    private static void milk_tea_manage(Scanner scanner) {
        boolean running = true;

        while (running) {
            System.out.println("----奶茶管理系统----");
            System.out.println("1. 查看全部奶茶");
            System.out.println("2. 添加新品");
            System.out.println("3. 下架奶茶");
            System.out.println("4. 修改奶茶信息");
            System.out.println("5. 返回主菜单");

            try {
                System.out.print("请选择操作 (1-5): ");
                int choice = Integer.parseInt(scanner.nextLine());

                if (choice == 5) {
                    app_show(scanner);
                    running = false;
                    continue;
                }

                MilkTeaOperation operation = MilkTeaOperationFactory.getOperation(choice);
                if (operation != null) {
                    operation.execute(scanner);
                } else {
                    System.out.println("无效选择，请重新输入。");
                }
            } catch (NumberFormatException e) {
                System.out.println("请输入有效的数字选项。");
            }
        }
    }








}
